# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=webrtc-audio-processing
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.1
pkgrel=1
pkgdesc="AudioProcessing library based on Google's implementation of WebRTC (mingw-w64)"
url="https://freedesktop.org/software/pulseaudio/webrtc-audio-processing/"
arch=('any')
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://gitlab.freedesktop.org/pulseaudio/${_realname}/-/archive/v${pkgver}/${_realname}-v${pkgver}.tar.gz"
        "0001-disable-backtrace-exception-handling.patch"
        "0002-pkgconfig-add-winmm.patch"
        "0003-enable-lrint-mingw.patch")
sha512sums=('50ee71900f49d32aecf3dd8c541fd4fe8097496fabbe5fe001691931987373c67fafdfce6648f3b2b971a1eb1883e1c9fdf015fe4cc91260bd40d753c7e538b4'
            '8274dd072a2fd9c9be45664c3f37090b0f18289d6e54df16a74295ff3220fa690853820e4fbb9598fb33a1bc2b39e94a2125c0bdda2b69621df0ea17047f4dc7'
            '8e08b607b04900a286bbf4be4aee6d2ded39a364a03cf26a836bbe5a50e45a0c0267b4f5dd8979eebaf1c3dc7b171f7b397163982087f85efa700e2fa0c055e0'
            '26d85ef98f1e9a1f86db873ac72b959dfd5e2031e212456b8a5b9b10c67332e9fa41264035fee17dce2b2da7691e589b4873dd1b8b09fda3b2de7591f6cc85b4')

prepare() {
  cd "${srcdir}/${_realname}-v${pkgver}"

  patch -Np1 -i "${srcdir}/0001-disable-backtrace-exception-handling.patch"
  patch -Np1 -i "${srcdir}/0002-pkgconfig-add-winmm.patch"
  patch -Np1 -i "${srcdir}/0003-enable-lrint-mingw.patch"
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-v${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  cd "${srcdir}/${_realname}-v${pkgver}"
  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
